package com.visitorspecials.tankbattle.server;

import java.util.*;

public class Particles extends Actor
{
	Particle[][] particles;
	
	public Particles(Actor actr)
	{
		super(actr.getTextureName(), actr.getLocation(), actr.getSize(), actr.getList());
		
		int size = (int) Math.sqrt(actr.getSize());
		particles = new Particle[(int) actr.getSize()][(int) actr.getSize()];
		
		for(int i = 0; i < particles.length;i++)
		{
			for(int k = 0; k < particles[0].length;k++)
			{
				particles[i][k] = new Particle(actr.getTextureName(), actr.getLocation() ,size , new Vector2( (float) Math.random(), (float) Math.random()), actr.getList(), (k/size), (k+1/size), (i/size), (i+1/size));      
				particles[i][k].setHeading(actr.getHeading());
			}
		}
	}
	
	public String toString()
	{
		String returnString = "";
		for(int i = 0; i < particles.length;i++)
		{
			for(int k = 0; k < particles[0].length;k++)
			{
				returnString+=particles[i][k].toString();
			}
		}
		
		return returnString;
	}
	
	public void update()
	{
		int gone = 0;
		for(int i = 0; i < particles.length;i++)
		{
			for(int k = 0; k < particles[0].length;k++)
			{
				if(particles[i][k] == null)
				{
					gone++;
				}
			}
		}
		
		if(gone == particles.length*particles.length)
		{
			this.removeSelfFromList();
		}
	}
}
